package com.ngds.library.downloadcenter;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * DownloadEnvironmentSettings
 * Description:下载网络条件,可修改下载设置实现自动控制也可以由app开发者手动控制。目前GameStore是采用开发者手动控制
 * Author:walker lx
 * Date :14-5-14
 */
public class DownloadEnvironmentSettings {
    //default settting is AUTO_SWITCH only
    public static final int WIFY_ONLY = AppDownloadManager.Request.NETWORK_WIFI;
    public static final int AUTO_SWITCH =
        AppDownloadManager.Request.NETWORK_WIFI | AppDownloadManager.Request.NETWORK_MOBILE;
    private static final String TAG = "DownloadEnvironmentSettings";


    public static int getCurrentUserDownloadSettings(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(TAG, 0);
        return sharedPreferences.getInt(TAG, AUTO_SWITCH);
    }


    public static void setDownloadSettings(Context context, int setting) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(TAG, 0);
        sharedPreferences.edit().putInt(TAG, setting).commit();
        boolean isWifyOnly = (setting == WIFY_ONLY);
        AppDownloadHelperImpl.getInstance(context).changeDownloadNetSetting(context, isWifyOnly);
    }

    public static boolean isAllowedMobileDownload(Context context) {
        return getCurrentUserDownloadSettings(context) == AUTO_SWITCH;
    }
}
